<template>
    <view>
        <view style="padding: 10px">累计返利：{{ totalRebates || 0 }} 元</view>
        <uni-list>
            <uni-list-item v-for="(item, index) in rebates" :key="index" :title="UTCTimeToLocal(item.cpTime)" :rightText="'¥' + item.cpMone" />
        </uni-list>
    </view>
</template>

<script>
import { getItemRebateByCiUuid } from "../../utils/api";
import { mapGetters } from "vuex";

export default {
    components: {},
    data() {
        return {
            rebates: [],
            totalRebates: 0,
        };
    },

    async onLoad() {
        await this.loadRebates();
    },

    computed: {
        ...mapGetters({
            userInfo: "personInfo/userInfo",
            activity: "activityInfo/activity",
        }),
    },

    methods: {
        async loadRebates() {
            if (!this.userInfo.ciUuid) return;
            let res = await getItemRebateByCiUuid({ ciUuid: this.userInfo.ciUuid, gpUuid: this.activity?.gpUuid });
            if (res) {
                this.rebates = res.rebates || [];
                this.totalRebates = res.totalRebates || 0;
            }
        },
    },
};
</script>

<style lang="scss" scoped></style>
